package com.xyc.springcloud.service;

import com.xyc.springcloud.pojo.Dept;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

// 服务降级
@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory {
    @Override
    public DeptClientService create(Throwable cause) {
        //调用失败就返回
        return new DeptClientService() {

            @Override
            public Dept queryById(Integer id) {
                return new Dept()
                        .setDeptno(id)
                        .setDname("id=>" + id + ",没有对应的信息,客户端提供了降级的信息，这个服务现在已经被关闭")
                        .setDb_source("没有数据库");
            }

            @Override
            public List<Dept> queryAll() {
                return null;
            }

            @Override
            public Boolean addDept(Dept dept) {
                return null;
            }
        };
    }
}
